package com.byxy.ssm.demo.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.byxy.ssm.demo.dao.ForumDao;
import com.byxy.ssm.demo.dao.TabDao;
import com.byxy.ssm.demo.dao.TipDao;
import com.byxy.ssm.demo.dao.UserDao;
import com.byxy.ssm.demo.entity.Forum;
import com.byxy.ssm.demo.entity.Tab;
import com.byxy.ssm.demo.entity.Tip;
import com.byxy.ssm.demo.entity.User;
import com.byxy.ssm.demo.service.TipService;
import com.byxy.ssm.demo.vo.TipVO;

@Service
@Transactional
public class TipServiceImpl implements TipService{
	@Autowired
	private TipDao tipDao;
	@Autowired
	private UserDao userDao;
	@Autowired
	private ForumDao forumDao;
	@Autowired
	private TabDao tabDao;
	
	@Override
	public void addRelease(Tip tip) {
		tipDao.addRelease(tip);
	}
	
	@Override
	public TipVO findById(Integer tipId) {
		Tip tip = tipDao.finById(tipId);
		TipVO tipVo = new TipVO();
		BeanUtils.copyProperties(tip, tipVo);
		User u = userDao.getById(tip.getUserId());
		if (u.getUserNick() != null && u.getUserNick().equals("")) {
			tipVo.setUserName(u.getUserNick());
		} else {
			tipVo.setUserName(u.getUserName());
		}
		Tab tab = tabDao.getById(tip.getTabId());
		tipVo.setTabName(tab.getTabName());
		Forum forum = forumDao.getById(tab.getForumId());
		tipVo.setForumName(forum.getForumName());
		
		
		return tipVo;
	}

	@Override
	public void addContent(Integer tipId, String replyContent) {
		tipDao.addContent(tipId,replyContent);
	}

	
}
